home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / procssng / ccs / ccs-11tl.lha / lbl / xview / genial / ui / genial.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-07-14  |  12.3 KB  |  534 lines

  1.  
  2. /*
  3.  * genial.c
  4.  */
  5.  
  6. #include <stdio.h>
  7. #include <string.h>
  8. #include <strings.h>
  9. #include <xview/cms.h>
  10. #include "display.h"
  11. #include "ui.h"
  12. #include "sm.h"
  13. #include "log.h"
  14. #include "histo_ui.h"
  15. #include "trace_ui.h"
  16. #include "comment_ui.h"
  17. #include "gfm_ui.h"
  18.  
  19. Xv_Window paintwin;
  20. Display  *display;
  21. Visual   *winv;
  22. XID       xid;
  23. GC        gc;
  24. int       depth;
  25.  
  26. int       line_mode = CLICK;
  27. int       clean_mode = 0;
  28.  
  29. Attr_attribute INSTANCE;
  30.  
  31. /*
  32.  * Global object definitions.
  33.   */
  34.  
  35. main_control_ctrlwin_objects *base_win;
  36. main_control_imgwin_objects *genial_imgwin;
  37. file_window1_objects *file_win;
  38. display_ctrlwin_objects *disp_ctrl;
  39. gfm_popup_objects *gfm_ctrl;
  40. comment_comm_win_objects *comment_win;
  41.  
  42. struct disp_win *img_win;
  43.  
  44. char     *func_names[] =
  45. {"Trace", "Histogram", "Zoom", "Distance",
  46.  "Angle Measure", "Annotate", "Comment"};
  47.  
  48. extern void imgwin_resize_proc();
  49.  
  50. /* function to initialize the components of the User Interface */
  51. void
  52. init_ui()
  53. {
  54.     Cms cms;
  55.     static Xv_singlecolor colors[] = {
  56.     { 255, 0, 0 }, /* red */
  57.         { 0, 0, 255 }, /* blue */
  58.     };
  59.  
  60.     XGCValues gcval;
  61.     gfm_popup_objects *gfm_initialize();
  62.  
  63.     /*
  64.      * Initialize user interface components.
  65.      */
  66.     base_win = main_control_ctrlwin_objects_initialize(NULL, NULL);
  67.     genial_imgwin = main_control_imgwin_objects_initialize(NULL, base_win->ctrlwin);
  68.     file_win = file_window1_objects_initialize(NULL, base_win->ctrlwin);
  69.     disp_ctrl = display_ctrlwin_objects_initialize(NULL, base_win->ctrlwin);
  70.     comment_win = comment_comm_win_objects_initialize(NULL, base_win->ctrlwin);
  71.     gfm_ctrl = gfm_initialize(NULL, file_win->window1, "Genial File Control");
  72.  
  73.     /* set color for help text */
  74.     cms = (Cms) xv_create(NULL, CMS,
  75.               CMS_CONTROL_CMS, TRUE,
  76.               CMS_SIZE, CMS_CONTROL_COLORS + 2,
  77.               CMS_COLORS, colors,
  78.               NULL);
  79.     xv_set(base_win->controls2, WIN_CMS, cms, NULL);
  80.     /* set all messages to red */
  81.     xv_set(base_win->statmsg1, PANEL_ITEM_COLOR, CMS_CONTROL_COLORS, NULL);
  82.     xv_set(base_win->statmsg2, PANEL_ITEM_COLOR, CMS_CONTROL_COLORS, NULL);
  83.     xv_set(base_win->statmsg3, PANEL_ITEM_COLOR, CMS_CONTROL_COLORS, NULL);
  84.     xv_set(base_win->statmsg4, PANEL_ITEM_COLOR, CMS_CONTROL_COLORS, NULL);
  85.  
  86.     /* allocate and initialize img_win */
  87.  
  88.     img_win = (struct disp_win *) malloc(sizeof(struct disp_win));
  89.     if (img_win == NULL) {
  90.     perror("malloc");
  91.     exit(0);
  92.     }
  93.     img_win->d_win = (Xv_Window) genial_imgwin->imgwin;
  94.     img_win->d_canv = (Canvas) genial_imgwin->imgcanv;
  95.     img_win->d_paintwin = (Xv_Window) canvas_paint_window(img_win->d_canv);
  96.     img_win->d_xid = (XID) xv_get(img_win->d_paintwin, XV_XID);
  97.  
  98.     /* set up display, winv and GC for future X calls */
  99.     display = (Display *) xv_get(img_win->d_win, XV_DISPLAY);
  100.     depth = DisplayPlanes(display, DefaultScreen(display));
  101.  
  102.     if (depth != 8 && depth != 24) {
  103.     fprintf(stderr, "Error: This program requires an 8 or 24-bit color monitor \n");
  104.     exit(0);
  105.     }
  106.     winv = DefaultVisual(display, DefaultScreen(display));
  107.  
  108.     /* set up a GC with 'reasonable' values */
  109.     gcval.foreground = BlackPixel(display, DefaultScreen(display));
  110.     gcval.background = WhitePixel(display, DefaultScreen(display));
  111.     gcval.clip_mask = None;
  112.     gc = XCreateGC(display, img_win->d_xid, GCForeground | GCBackground |
  113.            GCClipMask, &gcval);
  114.  
  115.     xv_set(file_win->window1, XV_SHOW, FALSE, NULL);
  116.  
  117.     xv_set(base_win->infomesg, PANEL_LABEL_STRING, "  ", NULL);
  118.     xv_set(base_win->image_fname, PANEL_LABEL_STRING, "image not loaded", NULL);
  119.     panel_paint(base_win->infomesg, PANEL_CLEAR);
  120.     panel_paint(base_win->image_fname, PANEL_CLEAR);
  121.  
  122.     xv_set(base_win->log_num, PANEL_LABEL_STRING, "1", NULL);
  123.     xv_set(base_win->message9, PANEL_LABEL_STRING, "  ", NULL);
  124. }
  125.  
  126. lab_info(val, m)
  127.     char     *val;
  128.     int       m;
  129. {
  130.     switch (m) {
  131.     case 1:
  132.     xv_set(base_win->statmsg1,
  133.            PANEL_LABEL_STRING, val,
  134.            NULL);
  135.     break;
  136.     case 2:
  137.     xv_set(base_win->statmsg2,
  138.            PANEL_LABEL_STRING, val,
  139.            NULL);
  140.     break;
  141.     case 3:
  142.     xv_set(base_win->statmsg3,
  143.            PANEL_LABEL_STRING, val,
  144.            NULL);
  145.     break;
  146.     case 4:
  147.     xv_set(base_win->statmsg4,
  148.            PANEL_LABEL_STRING, val,
  149.            NULL);
  150.     break;
  151.     }
  152.  
  153. }
  154.  
  155. clear_info()
  156. {
  157.     char     *b;
  158.     b = (char *) xv_get(base_win->statmsg1, PANEL_LABEL_STRING);
  159.     xv_set(base_win->statmsg1,
  160.        PANEL_LABEL_STRING, NULL,
  161.        NULL);
  162.     free(b);
  163.     b = (char *) xv_get(base_win->statmsg2, PANEL_LABEL_STRING);
  164.     xv_set(base_win->statmsg2,
  165.        PANEL_LABEL_STRING, NULL,
  166.        NULL);
  167.     free(b);
  168.     b = (char *) xv_get(base_win->statmsg3, PANEL_LABEL_STRING);
  169.     xv_set(base_win->statmsg3,
  170.        PANEL_LABEL_STRING, NULL,
  171.        NULL);
  172.     free(b);
  173.     b = (char *) xv_get(base_win->statmsg4, PANEL_LABEL_STRING);
  174.     xv_set(base_win->statmsg4,
  175.        PANEL_LABEL_STRING, NULL,
  176.        NULL);
  177.     free(b);
  178.  
  179.     panel_paint(base_win->statmsg1, PANEL_CLEAR);
  180.     panel_paint(base_win->statmsg2, PANEL_CLEAR);
  181.     panel_paint(base_win->statmsg3, PANEL_CLEAR);
  182.     panel_paint(base_win->statmsg4, PANEL_CLEAR);
  183. }
  184.  
  185. /*
  186.  * label_event() -- takes an event and placs the x,y and gray values under
  187.  * the point into the ctrlwin
  188.  *
  189.  */
  190.  
  191. label_event(event)
  192.     Event    *event;
  193. {
  194.     char      tstr[8];
  195.     int       x = dtoi(event_x(event)), y = dtoi(event_y(event));
  196.     unsigned  gray;
  197.  
  198.     if (pt_in_xim(x, y, orig_ximg) == 0)
  199.     return;
  200.     gray = dval(x, y, orig_img, 0);
  201.     sprintf(tstr, "%d", x);
  202.     xv_set(base_win->xlabel,
  203.        PANEL_LABEL_STRING, tstr,
  204.        NULL);
  205.     sprintf(tstr, "%d", y);
  206.     xv_set(base_win->ylabel,
  207.        PANEL_LABEL_STRING, tstr,
  208.        NULL);
  209.     sprintf(tstr, "%d", gray);
  210.     xv_set(base_win->glabel,
  211.        PANEL_LABEL_STRING, tstr,
  212.        NULL);
  213. }
  214.  
  215. /*
  216.  * label_img() -- fill the imglabel member of the base window with the
  217.  * geometry of the image, extrema, and width
  218.  *
  219.  */
  220. label_img(img)
  221.     struct img_data *img;
  222. {
  223.     char      tstr[80];
  224.  
  225.     sprintf(tstr, "%dx%d,[%d:%d],", img->width, img->height,
  226.         img->minv, img->maxv);
  227.     switch (img->dsize) {
  228.     case 1:
  229.     strcat(tstr, "byte");
  230.     break;
  231.     case 2:
  232.     strcat(tstr, "short");
  233.     break;
  234.     case 4:
  235.     strcat(tstr, "integer");
  236.     break;
  237.     default:
  238.     XBell(display, 0);
  239.     fprintf(stderr, "No such format!\n");
  240.     break;
  241.     }
  242.  
  243.     xv_set(base_win->imglabel,
  244.        PANEL_LABEL_STRING, tstr,
  245.        NULL);
  246.     /* set the frame numbers and turnon the buttons if appropriate */
  247.     sprintf(tstr, "%d/%d", img->cframe, img->nframes);
  248.     xv_set(base_win->frame_stat,
  249.        PANEL_LABEL_STRING, tstr,
  250.        NULL);
  251.     set_frame_buttons(img);
  252. }
  253.  
  254. /*
  255.  * Notify callback function for `quit'.
  256.  */
  257. void
  258. quit_proc(item, event)
  259.     Panel_item item;
  260.     Event    *event;
  261. {
  262.     int       result;
  263.     Panel     panel = (Panel) xv_get(item, PANEL_PARENT_PANEL, NULL);
  264.  
  265.     if (orig_img != NULL) {
  266.     if (logtail != NULL && !orig_img->file_saved) {
  267.         result = notice_prompt(panel, NULL,
  268.                    NOTICE_MESSAGE_STRINGS,
  269.                    "Exit without saving log ?", NULL,
  270.                    NOTICE_BUTTON_YES, "Yes",
  271.                    NOTICE_BUTTON_NO, "No",
  272.                    NULL);
  273.  
  274.         if (result == NOTICE_NO)
  275.         return;
  276.     }
  277.     }
  278.     state_dispatch(QUIT, NULL);
  279. }
  280.  
  281. /*
  282.  * Notify callback function for `file'.
  283.  */
  284. void
  285. file_proc(item, event)
  286.     Panel_item item;
  287.     Event    *event;
  288. {
  289.     if (xv_get(file_win->window1, XV_SHOW, NULL) == FALSE)
  290.     xv_set(file_win->window1,
  291.            XV_SHOW, TRUE, FRAME_CLOSED, FALSE, NULL);
  292.     else {
  293.     xv_set(file_win->window1,
  294.            XV_SHOW, FALSE, NULL);
  295.     }
  296. }
  297.  
  298. /*
  299.  * Notify callback function for `display'.
  300.  */
  301. void
  302. dpyopt_proc(item, event)
  303.     Panel_item item;
  304.     Event    *event;
  305. {
  306.     if (xv_get(disp_ctrl->ctrlwin, XV_SHOW, NULL) == FALSE)
  307.     xv_set(disp_ctrl->ctrlwin,
  308.            XV_SHOW, TRUE, FRAME_CLOSED, FALSE, NULL);
  309.     else
  310.     xv_set(disp_ctrl->ctrlwin,
  311.            XV_SHOW, FALSE, NULL);
  312.  
  313. #ifdef DEBUG
  314.     fputs("genial: dpyopt_proc\n", stderr);
  315. #endif
  316. }
  317.  
  318.  
  319. void
  320. refresh_proc(item, event)
  321.     Panel_item item;
  322.     Event    *event;
  323. {
  324.     imgwin_repaint_proc(img_win->d_canv, img_win->d_paintwin, display,
  325.             img_win->d_xid, NULL);
  326.  
  327. }
  328.  
  329. /*
  330.  * Notify callback function for `prev'.
  331.  */
  332. void
  333. prev_proc(item, event)
  334.     Panel_item item;
  335.     Event    *event;
  336. {
  337.     state_dispatch(BACK, NULL);
  338. }
  339.  
  340. /*
  341.  * Notify callback function for `next'.
  342.  */
  343. void
  344. next_proc(item, event)
  345.     Panel_item item;
  346.     Event    *event;
  347. {
  348.     state_dispatch(FORW, NULL);
  349. }
  350.  
  351. /*
  352.  * Notify callback function for `func_sel'.
  353.  */
  354. void
  355. func_sel_proc(item, value, event)
  356.     Panel_item item;
  357.     int       value;
  358.     Event    *event;
  359. {
  360. #ifdef DEBUG
  361.     fprintf(stderr, "genial: func_sel_proc: value: %u\n", value);
  362. #endif
  363.     xv_set(base_win->reg_type, PANEL_VALUE, 0, NULL);
  364.     state_dispatch(FMENU, (caddr_t *) & value);
  365. }
  366.  
  367. /*
  368.  * Notify callback function for `eval'.
  369.  */
  370. void
  371. eval_proc(item, event)
  372.     Panel_item item;
  373.     Event    *event;
  374. {
  375.     state_dispatch(EVAL, NULL);
  376. }
  377.  
  378. /*
  379.  * Notify callback function for `clear'.
  380.  */
  381. void
  382. clear_proc(item, event)
  383.     Panel_item item;
  384.     Event    *event;
  385. {
  386.     state_dispatch(CLEAR, NULL);
  387.     xv_set(base_win->infomesg, PANEL_LABEL_STRING, "  ", NULL);
  388.     panel_paint(base_win->infomesg, PANEL_CLEAR);
  389.  
  390. }
  391.  
  392. /*
  393.  * Notify callback function for `lmode'.
  394.  */
  395. void
  396. linemode_proc(item, value, event)
  397.     Panel_item item;
  398.     int       value;
  399.     Event    *event;
  400. {
  401.     void      reg_type_proc();
  402.  
  403. #ifdef DEBUG
  404.     fprintf(stderr, "genial: linemode_proc: value: %u\n", value);
  405. #endif
  406.  
  407.     if (getnpoints() == 0) {    /* can't change modes in the middle of
  408.                  * defining a region */
  409.     line_mode = value;
  410.     reg_type_proc((Panel_item) NULL, (int) xv_get(base_win->reg_type,
  411.                           PANEL_VALUE), (Event *) NULL);
  412.     } else {
  413.     xv_set(item, PANEL_VALUE, line_mode, NULL);
  414.     XBell(display, 0);
  415.     fprintf(stderr, "Error: Can't change mode while defining a region. \n");
  416.     }
  417. }
  418.  
  419. /*
  420.  * Event callback function for `imgcanv'.
  421.  */
  422. Notify_value
  423. imgwin_event_proc(win, event, arg, type)
  424.     Xv_window win;
  425.     Event    *event;
  426.     Notify_arg arg;
  427.     Notify_event_type type;
  428. {
  429. #ifdef STRONGDEBUG
  430.     fprintf(stderr, "genial: imgwin_event_proc: event %d\n", event_id(event));
  431. #endif
  432.  
  433.     if (orig_img == NULL)
  434.     return notify_next_event_func(win, (Notify_event) event, arg, type);
  435.  
  436.     if (event_x(event) >= orig_img->width)
  437.     return notify_next_event_func(win, (Notify_event) event, arg, type);
  438.     if (event_y(event) >= orig_img->height)
  439.     return notify_next_event_func(win, (Notify_event) event, arg, type);
  440.  
  441.     if (event_is_ascii(event) && event_is_down(event)) {
  442.     add_char((char) event_id(event));
  443.     return notify_next_event_func(win, (Notify_event) event, arg, type);
  444.     }
  445.     if (getstate() != IMG_UNLOADED)
  446.     label_event(event);
  447.  
  448.     /* only continue is mouse button event */
  449.     if (event_id(event) != BUT(1) && event_id(event) != BUT(2) &&
  450.     event_id(event) != BUT(3) && event_id(event) != LOC_DRAG)
  451.     return notify_next_event_func(win, (Notify_event) event, arg, type);
  452.  
  453.     if (event_is_down(event)) {
  454. #ifdef DEBUG
  455.     printf("button down.\n");
  456. #endif
  457.     state_dispatch(IMG_BUT, (caddr_t) event);
  458.     }
  459.     if (event_is_up(event)) {
  460. #ifdef DEBUG
  461.     printf("button released.\n");
  462. #endif
  463.     state_dispatch(IMG_BUT, (caddr_t) event);
  464.     }
  465.     return notify_next_event_func(win, (Notify_event) event, arg, type);
  466. }
  467.  
  468. /*
  469.  * Event callback function for `imgwin'.
  470.  */
  471. Notify_value
  472. main_control_imgwin_event_callback(win, event, arg, type)
  473.     Xv_window win;
  474.     Event    *event;
  475.     Notify_arg arg;
  476.     Notify_event_type type;
  477. {
  478.  
  479. #ifdef DEBUG
  480.     fprintf(stderr, "genial: genial_imgwin_event_callback: event %d\n",
  481.         event_id(event));
  482. #endif
  483.     /* gxv_start_connections DO NOT EDIT THIS SECTION */
  484.  
  485.     if (event_action(event) == WIN_RESIZE) {
  486.     imgwin_resize_proc(win, event, arg, type);
  487.     }
  488.     /* gxv_end_connections */
  489.  
  490.     return notify_next_event_func(win, (Notify_event) event, arg, type);
  491. }
  492.  
  493. /*
  494.  * Notify callback function for `clear_all'.
  495.  */
  496. void
  497. clear_all_proc(item, event)
  498.     Panel_item item;
  499.     Event    *event;
  500. {
  501.     struct logent *log;
  502.  
  503. #ifdef DEBUG
  504.     fputs("genial: clear_all_proc\n", stderr);
  505. #endif
  506.  
  507.     state_dispatch(CLEAR, NULL);/* clear current state first */
  508.  
  509.     clear_log();
  510.     fxn_reset();
  511.     fxn_init();
  512.     new_state(IMG_LOADED);
  513.  
  514.     xv_set(base_win->infomesg, PANEL_LABEL_STRING, "  ", NULL);
  515.     panel_paint(base_win->infomesg, PANEL_CLEAR);
  516.  
  517.     imgwin_repaint_proc(img_win->d_canv, img_win->d_paintwin, display,
  518.             img_win->d_xid, NULL);
  519. }
  520.  
  521. /*************************************************************/
  522.  
  523. void
  524. set_clean_mode(item, value, event)
  525.     Panel_item item;
  526.     int       value;
  527.     Event    *event;
  528. {
  529. #ifdef DEBUG
  530.     printf(" clean mode set to: %d \n", clean_mode);
  531. #endif
  532.     clean_mode = value;
  533. }
  534.